<template>
<div>
  <el-table :data="getterlist" border style="width: 100%" row-key="id">
    <el-table-column prop="id" label="编号" width="120"></el-table-column>
    <el-table-column prop="title" label="轮播图标题">
    </el-table-column>
    <el-table-column prop="img" label="图片">
      <template slot-scope="scope"  v-if="scope.row.img">
        <el-image
          style="width: 50px; height: 50px"
          :src="scope.row.img"
          fit="contain"
        ></el-image>
        </template>
    </el-table-column>
    <el-table-column prop="status" label="状态">
      <template slot-scope="scope">
        <el-tag type="primary" v-if="scope.row.status == 1">启用</el-tag>
        <el-tag type="danger" v-else>禁用</el-tag>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button size="mini" type="primary" @click="edit(scope.row.id)"
          >编辑</el-button
        >
        <el-button size="mini" type="danger" @click="del(scope.row.id)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
   </div>
</template>

<script>
import { delBanner } from "../../util/axios";
import {mapGetters,mapActions} from "vuex" 
export default {
  computed:{
    ...mapGetters({
        getterlist:"banner/gettersBannerlist"
    })
  },
  mounted() {
    this.bannerList();
  },
  methods: {
    ...mapActions({
        bannerList:"banner/getBannerActions"
    }),
    //编辑功能
    edit(id) {
      this.$emit("edit", id);
    },
    //删除功能
    del(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delBanner({id}).then((res) => {
            if (res.code == 200) {
              this.bannerList();
              this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },
  },
};
</script>

<style lang="stylus" scoped></style>